import java.util.*;
public class Solution {
    //JZ61 扑克牌顺子
    public boolean IsContinuous(int [] numbers) {
        HashSet<Integer>set=new HashSet<>();
        int min=Integer.MAX_VALUE;
        int max=Integer.MIN_VALUE;
        for(int i=0;i<numbers.length;i++){
            if(numbers[i]==0){
                continue;
            }
            if(set.contains(numbers[i])){
                return false;
            }else if(numbers[i]!=0){
                if(numbers[i]<min){
                    min=numbers[i];
                }
                if(numbers[i]>max){
                    max=numbers[i];
                }
                set.add(numbers[i]);
            }
        }
        if(max-min<5){
            return  true;
        }
        return false;
    }
    //JZ58 左旋转字符串
    public void revser(char [] str,int start,int end){
        int left=start;
        int right=end;
        while(left<right){
            char c=str[left];
            str[left]=str[right];
            str[right]=c;
            left++;
            right--;
        }

    }
    public String LeftRotateString(String str,int n) {
        if(str.length()==0){
            return "";
        }
        int len=str.length();
        n=n%len;
        char [] ret=str.toCharArray();
        //先整体翻转
        revser(ret,0,len-1);
        //再把前n个翻转
        revser(ret,0,len-n-1);
        //再把后len-n个翻转
        revser(ret,len-n,len-1);
        return new String(ret);
    }
    //JZ57 和为S的两个数字
    public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
        HashMap<Integer,Integer>map=new HashMap<>();
        ArrayList<Integer> arr=new ArrayList<>();
        for(int i=0;i<array.length;i++){
            int tmp=sum-array[i];
            if(map.containsKey(tmp)){
                arr.add(tmp);
                arr.add(array[i]);
                break;
            }else{
                map.put(array[i],i);
            }
        }
        return arr;
    }
}